/**
 * https://cabinjs.com/?id=koa
 */
const Cabin = require('cabin');
const requestReceived = require('request-received');
const responseTime = require('koa-better-response-time');
const requestId = require('koa-better-request-id');
const { Signale } = require('signale');

const cabin = new Cabin({
  logger: new Signale()
});

module.exports = (app) => {
  // adds request received hrtime and date symbols to request object
  // (which is used by Cabin internally to add `request.timestamp` to logs
  app.use(requestReceived);

  // adds `X-Response-Time` header to responses
  app.use(responseTime());

  // adds or re-uses `X-Request-Id` header
  app.use(requestId());

  // use the cabin middleware (adds request-based logging and helpers)
  app.use(cabin.middleware);
}